<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8">
  <title>工具借用</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="layuiadmin/style/admin.css" media="all">
  <style type="text/css">
.layui-table-cell .layui-form-radio {
	position: relative;
	top: 50%;
}
</style>
</head>
<body>
  <div class="layui-fluid">
  	 <div class="layui-form" lay-filter="layuiadmin-material-form-list" id="layuiadmin-material-form-list" style="padding: 20px 30px 0 0;">
    	<div class="layui-card">
	      <div class="layui-card-body">
	        <table id="LAY-toolinout-content-list" lay-filter="LAY-toolinout-content-list"></table> 
	      </div>
	      <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="layuiadmin-tooluse-form-submit" id="layuiadmin-tooluse-form-submit" value="确认添加">
		      <input type="button" lay-submit lay-filter="layuiadmin-tooluse-form-edit" id="layuiadmin-tooluse-form-edit" value="确认编辑">
		 </div>
		</div>
    </div>
  </div>

  <script src="layuiadmin/layui/layui.js"></script> 
  <script src="layuiadmin/js/form.js"></script>
  <script>
  layui.config({
    base: 'layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table', 'laydate'], function(){
    var table = layui.table
    ,admin = layui.admin
    ,laydate = layui.laydate
    ,form = layui.form;
    
  //日期范围
    laydate.render({
      elem: '#test-laydate-range-date'
      ,range: true
    });
    
    table.render({
        elem: '#LAY-toolinout-content-list'
        ,id: 'tab'
        ,url:'tooluse/findTooluseListJson'
        ,cellMinWidth: 20 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,cols: [[
           {type:'numbers', title: '序号'}
		  ,{field:'prisonercode', title: '借用人'}
          ,{field:'toolname', title: '工具名称'}
          ,{field:'inoutamount', title: '借用数量', sort: true,}
        ]]
      });
    
    //监听提交
    form.on('submit(layuiadmin-tooluse-form-submit)', function(obj){
    	
    	var data = layui.table.cache.tab;
    	
        if(data.length === 0){
            return layer.msg('没有工具借用');
        }
    	
    	//先赋值
    	obj.field.tooluseJSON = JSON.stringify(data)
    	
      	var field = obj.field; //获取提交的字段
      	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      	layer.confirm('确定操作?', function(index){
      		layer.msg('正在提交请稍候。。。', {icon: 16,time:'-1',shade : [0.5 , '#000' , true]});
      		admin.req({
    		     url: 'tooluse/saveTooluser' //实际使用请改成服务端真实接口
    	        ,data: field
    	        ,type: 'POST'
    	        ,done: function(res){
    	        	layer.msg(res.msg);
    	        }
         	});
        });
        //parent.layui.table.reload('LAY-tool-content-list'); //重载表格
        //parent.layer.close(index); //再执行关闭 
    });
    
  });
 
  
  </script>
</body>
</html>